package com.edu.exam.enums.examination;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 监控配置状态枚举
 *
 * <p>定义安全监控配置的状态，包括活跃、非活跃、草稿、审核中等状态。</p>
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-14
 */
public enum MonitoringConfigStatus implements BaseEnum {

    /** 活跃 */
    ACTIVE("ACTIVE", "活跃"),

    /** 非活跃 */
    INACTIVE("INACTIVE", "非活跃"),

    /** 草稿 */
    DRAFT("DRAFT", "草稿"),

    /** 已弃用 */
    DEPRECATED("DEPRECATED", "已弃用"),

    /** 禁用 */
    DISABLED("DISABLED", "禁用"),

    /** 审核中 */
    PENDING_REVIEW("PENDING_REVIEW", "审核中"),

    /** 已拒绝 */
    REJECTED("REJECTED", "已拒绝"),

    /** 已批准 */
    APPROVED("APPROVED", "已批准"),

    /** 测试中 */
    TESTING("TESTING", "测试中"),

    /** 归档 */
    ARCHIVED("ARCHIVED", "归档");

    private final String code;
    private final String description;

    MonitoringConfigStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值，默认返回ACTIVE
     */
    public static MonitoringConfigStatus fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            return ACTIVE;
        }

        for (MonitoringConfigStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return ACTIVE;
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值，默认返回ACTIVE
     */
    public static MonitoringConfigStatus fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            return ACTIVE;
        }

        for (MonitoringConfigStatus status : values()) {
            if (status.getDescription().equals(description)) {
                return status;
            }
        }
        return ACTIVE;
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}